/**
 * DeepPalette.java 2005. 6. 22.
 *
 * @copyrights 2004 PSIA Corp. All rights are reserved.
 */
package cs348a.color;

/**
 * A <code>GirbyPalette</code> defines a green, red, blue, yellow combination palette.
 *
 * @author Taeksoo Jung, YoungJin Kim
 */
public final class GirbyPalette extends BasicPalette {
	/** Singleton instance */
	public static final GirbyPalette INSTANCE = getInstance();
	
	/**
	 * Constructor for <code>GirbyPalette</code>.
	 * 
	 * @param reds array of red components
	 * @param greens array of green components
	 * @param blues array of blue components
	 */
	private GirbyPalette(byte[] reds, byte[] greens, byte[] blues) {
		super("Girby", reds, greens, blues);
	}
	
	/**
	 * Returns the singleton instance.
	 * 
	 * @return the singleton instance
	 */
	private static GirbyPalette getInstance() {
		// Creates arrays of components.
		byte[] reds = new byte[SIZE];
		byte[] greens = new byte[SIZE];
		byte[] blues = new byte[SIZE];

		// Constructs the components.
		for (int i = 0; i < SIZE; i++) {
			// Sets the red component.
			double f = (7.0 / 9.0) * ((SIZE - 1) / 2.0) * Math.cos(3 * Math.PI * i / (SIZE - 1)) - 
				((SIZE - 1) / (SIZE - 1)) * (2.0 / 9.0 * i) + (SIZE - 1) - ((SIZE - 1) / 2.0) * (7.0 / 9.0); 
			reds[i] = cutOff(f);
			
			// Sets the green component.
			f = (0.3 * Math.cos(2 * Math.PI * i / (SIZE - 1)) + 0.354 - 0.278 * i / (SIZE - 1)) * (SIZE - 1);
			greens[i] = cutOff(f);
			
			// Sets the blue component.
			if (i <= SIZE / 3) {
				f = (-Math.PI / 20.0 * Math.cos(3 * Math.PI * i / (SIZE - 1)) + 
						(Math.PI / 20.0) + (3.0 / 20.0) * i / (SIZE - 1)) * (SIZE - 1);				
			} else {
				f = (SIZE - 1) / 10.0;
			}
			blues[i] = cutOff(f);
		}
		
		return new GirbyPalette(reds, greens, blues);
	}
}
